/*
Simple Forum Auto Poster.
Copyright (C) 2011 Gianni Van Hoecke.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/
package gui.posting;

import domain.forumdata.tag.Tag;
import domain.forumdata.tag.Tags;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JTextField;

/**
 *
 * @author Gianni Van Hoecke <gianni.vh@gmail.com>
 */
public class PostParameterPanel extends javax.swing.JPanel
{

    /** Creates new form PostParameterPanel */
    public PostParameterPanel()
    {
        initComponents();

        DefaultComboBoxModel tags = new DefaultComboBoxModel();

        for(Tag tag : Tags.getTags())
        {
            tags.addElement(tag.getTagName());
        }

        this.cmbTags.setModel(tags);
    }

    public void loadCategories(DefaultComboBoxModel model)
    {
        this.cmbCategory.setModel(model);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lblCategory = new javax.swing.JLabel();
        cmbCategory = new javax.swing.JComboBox();
        lblTitle = new javax.swing.JLabel();
        txtTitle = new javax.swing.JTextField();
        lblSubtitle = new javax.swing.JLabel();
        txtSubtitle = new javax.swing.JTextField();
        lblTag = new javax.swing.JLabel();
        cmbTags = new javax.swing.JComboBox();

        setLayout(new java.awt.GridLayout(4, 2));

        lblCategory.setText("Category:");
        add(lblCategory);

        cmbCategory.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        add(cmbCategory);

        lblTitle.setText("Topic title:");
        add(lblTitle);
        add(txtTitle);

        lblSubtitle.setText("Topic subtitle: (when available)");
        add(lblSubtitle);
        add(txtSubtitle);

        lblTag.setText("Use tag: *");
        lblTag.setToolTipText("This will select a tag if available. If not, the tag will be added in front of the topic title.");
        add(lblTag);

        cmbTags.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        cmbTags.setToolTipText("This will select a tag if available. If not, the tag will be added in front of the topic title.");
        add(cmbTags);
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JComboBox cmbCategory;
    private javax.swing.JComboBox cmbTags;
    private javax.swing.JLabel lblCategory;
    private javax.swing.JLabel lblSubtitle;
    private javax.swing.JLabel lblTag;
    private javax.swing.JLabel lblTitle;
    private javax.swing.JTextField txtSubtitle;
    private javax.swing.JTextField txtTitle;
    // End of variables declaration//GEN-END:variables

    public JComboBox getCmbCategory() {
        return cmbCategory;
    }

    public JComboBox getCmbTags() {
        return cmbTags;
    }

    public JTextField getTxtSubtitle() {
        return txtSubtitle;
    }

    public JTextField getTxtTitle() {
        return txtTitle;
    }

    public void setButtonsEnabled(boolean enabled)
    {
        this.txtTitle.setEnabled(enabled);
        this.txtSubtitle.setEnabled(enabled);
        this.cmbCategory.setEnabled(enabled);
        this.cmbTags.setEnabled(enabled);
    }

    public void clearPost()
    {
        this.txtTitle.setText("");
        this.txtSubtitle.setText("");
        try
        {
            this.cmbCategory.setSelectedIndex(0);
            this.cmbTags.setSelectedIndex(0);
        }
        catch(Exception e){/* Ignore */}
    }
}